﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace PRE.catalog
{
    public partial class Frmdangkytaikhoan : DevExpress.XtraEditors.XtraForm
    {
        DAL.DangKyTaiKhoanDAL _dal = new DAL.DangKyTaiKhoanDAL();
        public Frmdangkytaikhoan()
        {
            InitializeComponent();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            var o = new DAL.Entities.Tai_Khoan()
            {
                taikhoan = txttaikhoan.Text.Trim(),

                matkhau = txtmatkhau.Text.Trim(),
                manv = txtmanhanvien.Text.Trim()
            };

            var oki = _dal.Insert(o);
            if (oki)
            {
                
                MessageBox.Show("Đã đăng ký thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                MessageBox.Show("Lỗi! Đăng ký thất bại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void txttaikhoan_EditValueChanged(object sender, EventArgs e)
        {
            string a = txttaikhoan.Text.Trim();
            if (a == "" || _dal.kt_taikhoan(a))
            {
                pictaikhoan2.Visible = true;
                pictaikhoan1.Visible = false;
            }
            else
            {
                pictaikhoan1.Visible = true;
                pictaikhoan2.Visible = false;
            }
        }

        private void txtmatkhau_EditValueChanged(object sender, EventArgs e)
        {
            if (txtmatkhau.Text.Trim() == "")
            {
                picmatkhau2.Visible = true;
                picmatkhau1.Visible = false;
            }
            else
            {
                picmatkhau1.Visible = true;
                picmatkhau2.Visible = false;
            }
        }

        private void txtmatkhaunhaplai_EditValueChanged(object sender, EventArgs e)
        {
            if (txtmatkhau.Text.Trim()==txtmatkhaunhaplai.Text.Trim())
            {
                picmatkhaunl1.Visible = true;
                picmatkhaunl2.Visible = false;
            }
            else
            {
                picmatkhaunl2.Visible = true;
                picmatkhaunl1.Visible = false;
            }
        }

        private void txtmanhanvien_EditValueChanged(object sender, EventArgs e)
        {
            string a = txtmanhanvien.Text.Trim();
            if (a == "" || !_dal.kt_nhanvien(a))
            {
                picnhanvien2.Visible = true;
                picnhanvien1.Visible = false;
            }
            else
            {
                picnhanvien1.Visible = true;
                picnhanvien2.Visible = false;
            }
        }
    }
}